package com.purchase.ml.resource.log;


import com.purchase.ml.bean.base.ApiRestResult;
import com.purchase.ml.bean.req.log.OperationLogQueryDto;
import com.purchase.ml.consts.CommonConsts;
import com.purchase.ml.consts.PermissionsConst;
import com.purchase.ml.entity.acc.SysUser;
import com.purchase.ml.enums.ManagerStatusEnum;
import com.purchase.ml.resource.BaseResource;
import com.purchase.ml.service.log.OperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kyyang
 * Created 2021-01-07
 */

@RestController
@RequestMapping("/operation_log")
@Api(tags = "操作日志")
public class OperationLogResource extends BaseResource {

    @Autowired
    private OperationLogService operationLogService;

    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("查询操作日志")
    @RequiresPermissions(PermissionsConst.ACTIVICY_LOG_QUERY)
    public ApiRestResult operationLogQuery(@RequestBody @Valid OperationLogQueryDto operationLogQueryDto) {
        SysUser currentUser = getCurrentUser();
        if(CommonConsts.ROLETYPE_ADMIN != currentUser.getRoleType()){
            operationLogQueryDto.setMerchantId(currentUser.getDealerId());
        }
        return ApiRestResult.ok(operationLogService.operationLogQuery(operationLogQueryDto));
    }


}
